import {Injectable} from '@angular/core';
import {NHttpClinet} from '@core/utils/http.client';
import {BaseService} from '@core/utils/BaseRequest';
import {SessionStorageService} from '@core/storage/storage.module';
import {ResponseModel} from "@core/utils/ResponseModel";

@Injectable()

export class QuestionTypeService extends BaseService {

  constructor(private _storage: SessionStorageService, http: NHttpClinet) {
    super('questionKind', http);
  }

  /* 添加类目 */
  QuestionAdd(qkid: string, kindName: string) {
    return new Promise((resolve, reject) => {
      this.http.post('http://www.easy-mock.com/mock/5a166a10d8031f24f9a782be/tester/questionKind', {qkid: qkid, kindName: kindName})
        .subscribe((response) => {
          if(response.result === '00000000') {
            this._storage.set('qkid', qkid);
            this._storage.set('kindName', kindName);
            resolve(response);
          }
        })
    })
  }

  /* 删除类目 */
  QuestionDelete(qkid: string) {
    return new Promise((resolve, reject) => {
      this.http.delete('http://www.easy-mock.com/mock/5a166a10d8031f24f9a782be/tester/questionKind/', {qkid: qkid})
        .subscribe((response) => {
          if(response.result === '00000000') {
            // this._storage.set('qkid', qkid);
            resolve(response);
          } else {
            reject(response);
          }
        })
    })
  }

  /* 修改类目 */
  // QuestionEdit(qkid: string, kindName: string) {
  //   return new Promise((resolve, reject) => {
  //     this.http.put('http://www.easy-mock.com/mock/5a166a10d8031f24f9a782be/tester/questionKind', {qkid: qkid, kindName: kindName})
  //       .subscribe((response: ResponseModel) => {
  //         resolve(response);
  //       })
  //   })
  // }
  QuestionEdit(questionKindqList: any) {
    return new Promise((resolve, reject) => {
      this.http.put(`${this.http.SERVER_URL}questionKind`, questionKindqList)
        .subscribe((response: ResponseModel) => {
          if(response.result === '00000000') {
            resolve(response);
          }
      })
    })
  }


  /*查询类目*/
  QuestionTypeList() {
    return new Promise((resolve, reject) => {
      this.http.get('http://ip:port/api/management/questionKind')
        .subscribe((response: ResponseModel) => {
          if(response.result === '00000000'){
            resolve(response);
          }
        })
    })
  }
}







